#ifndef NETWORKTHREAD_H
#define NETWORKTHREAD_H


#include <QMutex>
#include <QThread>
#include <QWaitCondition>
#include <QTcpSocket>
#include <QTime>
#include <QElapsedTimer>
#include <QQueue>

class HostInfo
{
    public:
    int hostIndex;
    QString hostName;
    QString HostIp;
    int HostPort;
};


class NetWorkThread : public QThread
{
    Q_OBJECT

public:
    explicit NetWorkThread(QObject *parent = nullptr);
    ~NetWorkThread();

    void transaction(const int hostIndex,const QString &hostName,const QString &hostIp,const int hostPort,int waitTimeout, const QString &request);
    //void threadQuit();
    void ReadData();
    void ReadError(QAbstractSocket::SocketError);

signals:
    void response2(const int devIndex,const QString &devName,const QString &res);
    void error(const QString &s);
    void timeout(const QString &s);

private:
    void run() override;
    HostInfo m_host;
    QQueue<QString> m_request;
    //QString m_request;
    int m_waitTimeout = 0;
    QMutex m_mutex;
    QWaitCondition m_cond;
    bool m_quit = false;
};
#endif // NETWORKTHREAD_H
